﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;
using System.Text;

namespace ALDIOrganizer
{
    public static class DataGridViewCellExtensionMethods
    {
        public static void ApplyStyle(this DataGridViewCell pCell, CachedStyle pStyle)
        {
            if (pCell.Style.BackColor != pStyle.Backcolor)
            {
                pCell.Style.BackColor = pStyle.Backcolor;
            }
            if (pCell.Style.ForeColor != pStyle.Forecolor)
            {
                pCell.Style.ForeColor = pStyle.Forecolor;
            }

            var _need_to_update_font =
                ((pCell.Style.Font == null) || (pStyle.Bold != pCell.Style.Font.Bold));
            if (!_need_to_update_font)
            {
                return;
            }
            FontStyle _font_style = pStyle.Bold ?
                                                    FontStyle.Bold :
                                                                       FontStyle.Regular;
            pCell.Style.Font = new Font(pCell.DataGridView.Font,
                                        _font_style);
        }
    }
}
